<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .v-enter, .v-leave-to{
      opacity: 0;
    }
    .v-enter-active, .v-leave-active, .v-move{
      transition: all 1s;
    }
    /* 让元素在离开的过程中脱标(脱离标准流) */
    .v-leave-active{
      position: absolute;
    }
    ul{
      position: relative;
    }
  </style>
</head>
<body>
  <div id="app">
    <input v-model="addItemTitle" @keyup.enter="addItem">
    <transition-group>
      <li v-for='item in items' @click="removeItem(item)" :key="item.id">{{item.title}}</li>
    </transition-group>
  </div>
</body>
<script src="../lib/vue.js"></script>
<script>
  new Vue({
    el: '#app',
    data: {
      items: [
        {id:1, title: '实例内容1'},
        {id:2, title: '实例内容2'},
        {id:3, title: '实例内容3'},
        {id:4, title: '实例内容4'}
      ],
      lastestId: 5,
      addItemTitle: ''
    },
    methods:{
      removeItem(item){
        var i = this.items.indexOf(item)
        this.items.splice(i, 1)
      },
      addItem(){
        var item = {
          id: this.lastestId,
          title: this.addItemTitle
        }
        this.lastestId++
        this.addItemTitle = ''
        this.items.push(item)
      }
    }
  })
</script>
</html>